'use strict';

const isPackageMissing = require('ember-cli-is-package-missing');
const SilentError = require('silent-error');

module.exports = {
  description: '[Classic Only] Generates a server directory for mocks and proxies.',

  normalizeEntityName() {},

  beforeInstall() {
    if (this.project.isViteProject()) {
      throw new SilentError('The server blueprint is not supported in Vite projects.');
    }
  },

  afterInstall(options) {
    let isMorganMissing = isPackageMissing(this, 'morgan');
    let isGlobMissing = isPackageMissing(this, 'glob');

    let areDependenciesMissing = isMorganMissing || isGlobMissing;
    let libsToInstall = [];

    if (isMorganMissing) {
      libsToInstall.push({ name: 'morgan', target: '^1.3.2' });
    }

    if (isGlobMissing) {
      libsToInstall.push({ name: 'glob', target: '^4.0.5' });
    }

    if (!options.dryRun && areDependenciesMissing) {
      return this.addPackagesToProject(libsToInstall);
    }
  },
};
